﻿using System;
using System.Web.UI.WebControls;

namespace DigDes.DSchool.SUPS.Web.UI
{
    public partial class CargoForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void OnSelectedIndexChanged(object sender, EventArgs e)
        {
            GridView1.DataBind();
        }

        protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';";
                e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
                e.Row.ToolTip = "Click to select row";
                e.Row.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
            }       
        } 

        protected void Edit_Click(object sender, EventArgs e)
        {
            DetailsView1.ChangeMode(DetailsViewMode.Edit);
            DetailsView1.DataBind();
        }

        protected void Add_Click(object sender, EventArgs e)
        {
            if (DetailsView1.CurrentMode != DetailsViewMode.Insert)
                DetailsView1.ChangeMode(DetailsViewMode.Insert);
        }

        protected void Delete_Click(object sender, EventArgs e)
        {
            GridView1.DeleteRow(GridView1.SelectedIndex);
        }

        protected void Save_Click(object sender, EventArgs e)
        {
            if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
            {
                DetailsView1.InsertItem(true);             
            }
            if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
            {
                DetailsView1.UpdateItem(true);
                GridView1.DataBind();
            }
            if (DetailsView1.CurrentMode != DetailsViewMode.ReadOnly)
                DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
            DetailsView1.DataBind();
        }

        protected void Cancel_Click(object sender, EventArgs e)
        {
            if (DetailsView1.CurrentMode != DetailsViewMode.ReadOnly)
                DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
            DetailsView1.DataBind();
        }

        protected void Load_Button_Click(object sender, EventArgs e)
        {
            DigDes.DSchool.SUPS.DataAccess.Database.DataRdr_Cargo.UploadImage(((TextBox)FormViewForImage.FindControl("Cargo_ID")).Text, FileUpload1.FileBytes);
        }
    }
}